<#import "../../../config/config.ftl" as config />
<html>
<head lang="en">
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=Edge">
    <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
    <title>选择菜单</title>
<@config.bootCSS></@config.bootCSS>
<@config.jstreeCSS></@config.jstreeCSS>
<@config.styleCSS></@config.styleCSS>
<@config.themesCSS></@config.themesCSS>
</head>
<body>

<div class="container-fluid">

    <div class="row">
        <div id="tree"></div>
    </div>

    <div style="position: fixed;bottom: 50px; margin-left: 100px;">
        <button type="button" class="btn btn-primary waves-effect" onclick="doSubmit()">确定</button>
    </div>
</div>

<@config.jqueryJS></@config.jqueryJS>
<@config.bootJS></@config.bootJS>
<@config.jstreeJS></@config.jstreeJS>

<script type="application/javascript">

    $(function () {
        var tree = $("#tree").jstree({
            "animation": 0,
            "check_callback": true,
            "themes": {"stripes": true},
            "plugins": ["checkbox"],
            'core': {
                'data': {
                    "url": function (node) {
                        var parentid;
                        if ("#" == node.id) {
                            parentid = 0;
                        } else {
                            parentid = node.id
                        }
                        return "${base}/sys/menu/getmenutreebyparentid.json?userid=${userId}&parentid=" + parentid;
                    },
                    "data": function (node) {
                        return {'id': node.id};
                    }
                }
            }
        });
    });

    function doSubmit() {
        var userId = ${userId};
        var checked = $("#tree").jstree().get_checked();
        var values = checked.join(",");
        $.ajax({
            url:"${base}/sys/user/saveusermenu.json",
            data:{userid:userId,menuids:values},
            type:"post",
            success:function(resp){
                if(resp.code ==200){
                    parent.closeWin();
                }else{
                    alert("操作失败,请重新操作");
                }
            },
            error:function(resp){
                alert("操作失败,请重新操作");
            }
        });
    }
</script>

</body>
        